package br.com.threads.entendendo;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class Semaforo {
	private JPanel ball;
	private static final int XSIZE = 25;
	private static final int YSIZE = 25;
	private int x;
	private int y;
	private Color color;
	
	//construtor
	public Semaforo(JPanel b_,Color c_, int x_, int y_){
		ball = b_;
		color = c_;
		x = x_;
		y = y_;
	}
	//metodo para atribuir cor ao semaforo
	public Color getColor(){
		return this.color;
	}
	public void setColor(Color c){
		this.color = c;
	}
	public void draw(){
		Graphics g = ball.getGraphics();
		g.setColor(color);
		g.fillOval(x, y, XSIZE, YSIZE);
		g.dispose();
	}
	//metodo para mudar as cores do farol
	public void mudarCores(){
		Graphics g = this.ball.getGraphics();
		if(this.getColor()== Color.GREEN){
			g.setColor(Color.YELLOW);
			this.setColor(Color.YELLOW);
		}else if(this.getColor()== Color.YELLOW){
			g.setColor(Color.RED);
			this.setColor(Color.RED);
		}else if(this.getColor() == Color.RED){
			g.setColor(Color.GREEN);
			this.setColor(Color.GREEN);
		}
		g.fillOval(x, y, this.XSIZE, this.YSIZE);
		g.dispose();
	}
	
}
